package com.wxh.back.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxh.back.entity.Rights;
import com.wxh.back.service.RightsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Rights)表控制层
 *
 * @author makejava
 * @since 2022-07-22 00:29:43
 */
@Api(tags = "权限管理")
@EnableSwagger2
@RestController
@RequestMapping("rights")
public class RightsController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private RightsService rightsService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param rights 查询实体
     * @return 所有数据
     */
    @ApiOperation(value = "查询所有权限", notes = "分页查询")
    @GetMapping("/selectAll")
    public R selectAll(Page<Rights> page, Rights rights) {
        return success(this.rightsService.page(page, new QueryWrapper<>(rights)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "查询单个权限", notes = "根据id查询")
    @GetMapping("/selectOne/{id}")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.rightsService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param rights 实体对象
     * @return 新增结果
     */
    @ApiOperation(value = "添加权限", notes = "添加权限接口")
    @PostMapping("/insert")
    public R insert(@RequestBody Rights rights) {
        return success(this.rightsService.save(rights));
    }

    /**
     * 修改数据
     *
     * @param rights 实体对象
     * @return 修改结果
     */
    @ApiOperation(value = "修改权限", notes = "修改权限接口")
    @PutMapping("/update")
    public R update(@RequestBody Rights rights) {
        return success(this.rightsService.updateById(rights));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation(value = "删除权限", notes = "删除权限接口")
    @DeleteMapping("/delete")
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.rightsService.removeByIds(idList));
    }
}

